<%--
  Created by IntelliJ IDEA.
  User: admin
  Date: 2021/11/1
  Time: 10:03
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <img src="http://192.168.1.113:8080/pet-images/${user.image}">
    <span>${user.nickname}</span>
    <hr>
    <div>
        <c:forEach var="pyq" items="${pyqs}">
            <div>
                <img src="http://192.168.1.113:8080/pet-images/${pyq.user.image}">
                <span>${pyq.user.nickname}</span>
            </div>
            <div>
                <span>${pyq.content}</span>
            </div>
            <div>
                <img src="http://192.168.1.113:8080/pet-images/${pyq.image}">
            </div>
            <div>
                <img class="zan" zanId="${pyq.id}" src="/images/zan.gif">
                <span class="zanUser">
                    <c:forEach var="zanUser" items="${pyq.zanUsers}">
                        ${zanUser.nickname}&nbsp;
                    </c:forEach>
                </span>
            </div>
        </c:forEach>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/jquery@1.12.4/dist/jquery.min.js" integrity="sha384-nvAa0+6Qg9clwYCGGPpDQLVpLNn0fRaROjHqs13t4Ggj3Ez50XnGQqc/r8MhnRDZ" crossorigin="anonymous"></script>
    <script>
        $(".zan").click(function () {
            let pyqId = $(this).attr("zanId");
            console.log(pyqId);
            let _this = $(this);
            $.post("clickZan",
                {"userId":${user.id},"pyqId":pyqId},
                function (res) {
                    if(res == "already"){
                        alert("该朋友圈已经点过赞了！");
                    }else{
                        console.log(res);
                        $.get("findPyqUsers?pyqId=" + pyqId,function (res) {
                            console.log(res);
                            let names = "";
                            for(let i = 0;i < res.length;i++){
                                names += res[i].nickname + " ";
                            }
                            _this.next("span").text(names);
                        })
                    }
                }
            );
        });
    </script>
</body>
</html>
